home *** CD-ROM | disk | FTP | other *** search
/ Apple II Magazines (PO) / Nibble Volume 11, No. 02 (1990-02)(MindCraft Publishing)(Side A).zip / Nibble Volume 11, No. 02 (1990-02)(MindCraft Publishing)(Side A).po / GS.ALARM.S < prev    next >
Text File  |  1996-12-24  |  12KB  |  519 lines

  1. ********************************
  2. *                              *
  3. *     GS.ALARM SOURCE CODE     *
  4. *                              *
  5. *     by Elwood J.C. Kureth    *
  6. *     Copyright(c) 1990        *
  7. *     MindCraft Publ. Corp.    *
  8. *     Concord, MA 01742        *
  9. *                              *
  10. ********************************
  11. *
  12. *
  13. *
  14. * MERLIN 8/16 ASSEMBLER
  15. *
  16. *
  17. *================== SECTION 0 ======================*
  18.  
  19.  
  20. BELL      = $FBDD        ;monitor bell routine
  21. COUT      = $FDED        ;monitor output routine
  22. HOME      = $FC58        ;monitor clear screen
  23. STROBE    = $C010        ;keyboard strobe
  24. INBUFF    = $200         ;input buffer use by GETLN2
  25. TEFLAG    = $3CE         ;previous time/event flag
  26. GETLN2    = $FD6F        ;monitor input routine
  27. VGCINT    = $C023        ;VGC interrupt register
  28. DOSWARM   = $3D0         ;DOS warmstart vector
  29. SCANINT   = $C032        ;Scan-line interrupt reg
  30. KEYBOARD  = $C000        ;read keyboard
  31. USERVECL  = $3FE         ;user interrupt vector-low
  32. USERVECH  = $3FF         ;user interrupt vector-high
  33.  
  34.           ORG $9001
  35.  
  36.           LDA #$00       ;set HIMEM to $9000
  37.           STA $4C
  38.           LDA #$90
  39.           STA $4D
  40.  
  41. BEGIN     JSR HOME
  42.  
  43. *================== SECTION 0a ===================*
  44.  
  45.            LDA TEFLAG    ;check flag to see if
  46.            CMP #"S"      ;alarm has already been
  47.            BNE CLEAR     ;set
  48.  
  49. RESET     LDY #$00       ;tell user that he/she
  50. :1        LDA RMSSG,Y    ;has already set alarm
  51.           BEQ DISPLAY
  52.           JSR COUT
  53.           INY
  54.           BRA :1
  55.  
  56. DISPLAY   LDY #$00       ;display current alarm
  57. :1        LDA TEBUFF,Y   ;time
  58.           JSR COUT
  59.           CPY #$07
  60.           BEQ ASK
  61.           INY
  62.           BRA :1
  63.  
  64. ASK       LDY #$00       ;ask the user if he/she
  65. :1        LDA RMSSG2,Y   ;wants to remove the old
  66.           BEQ GETANS     ;alarm and set a new one
  67.           JSR COUT
  68.           INY
  69.           BRA :1
  70.  
  71. GETANS    JSR GETLN2
  72.           LDA INBUFF
  73.           CMP #"Y"
  74.           BEQ CLEAR
  75.           CMP #"y"
  76.           BEQ CLEAR
  77.           CMP #"N"
  78.           BEQ QUIT
  79.           CMP #"n"
  80.           BEQ QUIT
  81.  
  82. YorN1     LDY #$00       ;tell user to type only
  83. :1        LDA CMSSG2,Y   ;a 'Y' or 'N'
  84.           BEQ GETANS
  85.           JSR COUT
  86.           INY
  87.           BNE :1
  88.  
  89. QUIT      JSR HOME       ;no change to alarm -
  90.           JMP DOSWARM    ;quit
  91.  
  92. *================== SECTION 1 ====================*
  93.  
  94. CLEAR     JSR HOME
  95.  
  96. * Display time prompt message.
  97.  
  98. TPROMPT   LDY #$00
  99. :1        LDA TMSSG,Y    ;print message
  100.           BEQ TIME       ;done, go to user for input
  101.           JSR COUT
  102.           INY
  103.           BNE :1
  104.  
  105. *================== SECTION 2 ====================*
  106.  
  107. TIME      JSR GETLN2     ;get time from user
  108.  
  109.           LDA INBUFF     ;is first character a
  110.           CMP #$91       ;CONTROL-Q?
  111.           BNE TIMCHK
  112.           JSR HOME       ;yes - quit APPEAR
  113.           JMP DOSWARM
  114.  
  115. * Ensure the user is entering the time in the correct
  116. * format and is using valid characters.
  117.  
  118. TIMCHK    TXA
  119.           TAY
  120.           DEY
  121.           LDA INBUFF,Y
  122.           CMP #"M"
  123.           BEQ CHECKP
  124.           CMP #"m"
  125.           BNE ERRORTIM
  126.           LDA #"M"
  127.           STA INBUFF,Y
  128.  
  129. CHECKP    DEY
  130.  
  131.           LDA INBUFF,Y
  132.           CMP #"P"
  133.           BEQ CHECKSP
  134.           CMP #"p"
  135.           BNE NOTP
  136.           LDA #"P"
  137.           STA INBUFF,Y
  138.           BRA CHECKSP
  139. NOTP      CMP #"A"
  140.           BEQ CHECKSP
  141.           CMP #"a"
  142.           BNE ERRORTIM
  143.           LDA #"A"
  144.           STA INBUFF,Y
  145.           BRA CHECKSP
  146.  
  147. ERRORTIM  JSR HOME
  148.           LDY #$00
  149. :1        LDA ERROR,Y
  150.           BEQ TIME
  151.           JSR COUT
  152.           INY
  153.           BNE :1
  154.  
  155. CHECKSP   DEY
  156.  
  157.           LDA INBUFF,Y
  158.           CMP #" "
  159.           BNE ERRORTIM
  160.           BRA CHKMIN1
  161.  
  162. CLEAR2    BRA CLEAR
  163.  
  164. CHKMIN1   DEY
  165.  
  166.           LDA INBUFF,Y
  167.           CMP #"0"
  168.           BMI ERRORTIM
  169.           CMP #":"
  170.           BPL ERRORTIM
  171.  
  172. CHKMIN2   DEY
  173.  
  174.           LDA INBUFF,Y
  175.           CMP #"0"
  176.           BMI ERRORTIM
  177.           CMP #"6"
  178.           BPL ERRORTIM
  179.  
  180. CHKCOLON  DEY
  181.  
  182.           LDA INBUFF,Y
  183.           CMP #":"
  184.           BNE ERRORTIM
  185.  
  186.           CPX #$08
  187.           BNE CHK07
  188.  
  189. CHK08     DEY
  190.  
  191.           LDA INBUFF,Y
  192.           CMP #"0"
  193.           BMI ERRORTIM
  194.           CMP #"3"
  195.           BPL ERRORTIM
  196.  
  197.           DEY
  198.  
  199.           LDA INBUFF,Y
  200.           CMP #"1"
  201.           BNE ERRORTIM
  202.  
  203.           BRA FULL8
  204.  
  205. CLEAR1    BRA CLEAR2
  206.  
  207. CHK07     DEY
  208.  
  209.           LDA INBUFF,Y
  210.           CMP #"1"
  211.           BMI ERRORTIM
  212.           CMP #":"
  213.           BPL ERRORTIM
  214.  
  215. * Transfer GETLN2 buffer (INBUFF) contents to
  216. * time/event buffer (TEBUFF).
  217.  
  218. ONLY7     LDA #" "       ;put SPACE character at
  219.           STA TEBUFF     ;start of buffer
  220.  
  221.           DEX            ;bring pointer back one
  222.                          ;byte to point at last
  223.                          ;character of time string-
  224.                          ;X now equals 6
  225.           LDY #$07
  226. :1        LDA INBUFF,X
  227.           STA TEBUFF,Y
  228.           DEX
  229.           DEY
  230.           BEQ DONE2
  231.           BNE :1
  232.  
  233. FULL8     DEX            ;X now equals 7
  234.           LDA INBUFF,X
  235.           STA TEBUFF,X
  236.           CPX #$00       ;beginning of buffer?
  237.           BEQ DONE2      ;yes - finished
  238.           BNE FULL8      ;no - get more
  239.  
  240. DONE2                    ;finished section 2
  241.  
  242. *================== SECTION 2a ===================*
  243.  
  244. * Give user a chance to change his time.
  245.  
  246. CHANGE    LDY #$00
  247. :1        LDA CMSSG,Y    ;print time ok? prompt mssg
  248.           BEQ CHNGTIME   ;done-go to user for input
  249.           JSR COUT
  250.           INY
  251.           BNE :1
  252.  
  253. CHNGTIME  JSR GETLN2
  254.           LDA INBUFF
  255.           CMP #"Y"
  256.           BEQ EPROMPT
  257.           CMP #"y"
  258.           BEQ EPROMPT
  259.           CMP #"N"
  260.           BEQ CLEAR1
  261.           CMP #"n"
  262.           BEQ CLEAR1
  263.  
  264. YorN2     LDY #$00       ;tell user to type only
  265. :1        LDA CMSSG2,Y   ;a 'Y' or 'N'
  266.           BEQ CHNGTIME
  267.           JSR COUT
  268.           INY
  269.           BNE :1
  270.  
  271.  
  272. *================== SECTION 3 ====================*
  273.  
  274. * Display event message prompt.
  275.  
  276. CLEAR4    JSR HOME
  277.  
  278. EPROMPT   LDY #$00
  279. :1        LDA EMSSG,Y    ;print event prompt mssg
  280.           BEQ EVENT      ;done - go to user for input
  281.           JSR COUT
  282.           INY
  283.           BNE :1
  284.  
  285. *================== SECTION 4 ====================*
  286.  
  287. EVENT     JSR GETLN2     ;get event from user
  288.  
  289.           LDA INBUFF     ;is first character a
  290.           CMP #$91       ;CONTROL-Q?
  291.           BNE XBUFF2
  292.           JSR HOME       ;yes - quit APPEAR
  293.           JMP DOSWARM
  294.  
  295. * Place the event in the time/event buffer
  296. * immediately after the time.
  297.  
  298. XBUFF2    LDX #$00
  299.           LDY #$08       ;point past end of time
  300.                          ;string in TEBUFF
  301. :1        LDA INBUFF,X
  302.           STA TEBUFF,Y
  303.           CMP #$8D       ;carriage return?
  304.           BEQ EPROMP2    ;yes - finished
  305.           INX
  306.           INY
  307.           BNE :1
  308.  
  309. *================== SECTION 4a ===================*
  310.  
  311. * Ask the user if the message is OK. Set a flag
  312. * (SETFLAG) if the message is OK. SETFLAG will
  313. * notify APPEAR that a time and an event have been
  314. * entered and the current alarm has not yet been
  315. * activated (gone off.)
  316.  
  317. EPROMP2   LDY #$00
  318. :1        LDA EMSSG2,Y   ;is message ok? prompt
  319.           BEQ GETANS2
  320.           JSR COUT
  321.           INY
  322.           BNE :1
  323.  
  324. GETANS2   JSR GETLN2
  325.           LDA INBUFF
  326.           CMP #"Y"
  327.           BEQ SETFLAG
  328.           CMP #"y"
  329.           BEQ SETFLAG
  330.           CMP #"N"
  331.           BEQ CLEAR4
  332.           CMP #"n"
  333.           BEQ CLEAR4
  334.  
  335. YorN3     LDY #$00       ;tell user to type only
  336. :1        LDA CMSSG2,Y   ;a 'Y' or 'N'
  337.           BEQ GETANS2
  338.           JSR COUT
  339.           INY
  340.           BNE :1
  341.  
  342. SETFLAG   LDA #"S"
  343.           STA TEFLAG
  344.           JSR HOME
  345.  
  346. *================== SECTION 5 ===================*
  347.  
  348. * Set user interrupt vector to address of main
  349. * routine (starting at MAIN), enable the 1-second
  350. * timer interrupt (bit 2 - VGCINT), and jump to
  351. * BASIC.
  352.  
  353. SETVEC    LDA #$EE
  354.           STA USERVECL
  355.           LDA #$91
  356.           STA USERVECH
  357.  
  358.           LDA VGCINT
  359.           ORA #%00000100
  360.           STA VGCINT
  361.  
  362.           JMP DOSWARM
  363.  
  364. *================== SECTION 6 ====================*
  365.  
  366. * Save some registers by pushing them on the stack,
  367. * place the processor in 16-bit mode and access the
  368. * miscellaneous tool ReadTimeASCII, which returns the
  369. * date and time as a string of characters.
  370.  
  371. MAIN      PHP
  372.           PHB
  373.           PHA
  374.           PHX
  375.           PHY
  376.  
  377.           CLC            ;emulation to native
  378.           XCE            ;e = 0 = native (enable)
  379.           REP $30        ;m & x = 0 (accumulator,
  380.                          ;memory locations, and
  381.                          ;index registers = 16 bits)
  382.  
  383. MTSTART   LDX #$0203     ;misc. tools startup
  384.           JSL $E10000    ;entry point for toolbox
  385.                          ;routines
  386.           PEA ^DTBUFF    ;pointer to input buffer
  387.                          ;(high word)
  388.           PEA DTBUFF     ;low word
  389.           LDX #$0F03     ;ReadTimeASCII
  390.           JSL $E10000    ;put string in memory
  391. MTSHUT    LDX #$0303     ;misc. tools shutdown
  392.           JSL $E10000
  393.  
  394.           SEC
  395.           XCE            ;back to emulation (8 bits)
  396.  
  397. *================== SECTION 7 ====================*
  398.  
  399. * Compare the time/event buffer to the IIGS date/time
  400. * buffer. When the times in both buffers match, buzz
  401. * the alarm and display the event message.
  402.  
  403. COMPARE   LDA TEBUFF+6   ;check for AM or PM.
  404.           CMP DTBUFF+18
  405.           BNE NOMATCH
  406.  
  407. OKAMPM    LDX #$04       ;AM/PM match; now check
  408.           LDY #$0D       ;the rest of the time.
  409.  
  410. GETMORE   LDA TEBUFF,X
  411.           CMP DTBUFF,Y
  412.           BNE NOMATCH
  413.           DEX
  414.           DEY
  415.           CPY #$08       ;end of DTBUFF? If so, the
  416.                          ;times match. Fall through
  417.                          ;to ALLMATCH and alert the
  418.                          ;user.
  419.           BNE GETMORE
  420.  
  421. ALLMATCH  LDA VGCINT     ;turn off interrupt
  422.           AND #%11111011
  423.           STA VGCINT
  424.  
  425.           LDY #$00
  426. :1        LDA CRS,Y
  427.           BEQ PRINT
  428.           JSR COUT
  429.           INY
  430.           BRA :1
  431.  
  432. PRINT     LDY #$08       ;point to start of event msg
  433. :1        LDA TEBUFF,Y   ;print event mssg.
  434.           JSR COUT
  435.           CMP #$8D
  436.           BEQ RINGBELL   ;go ring bell
  437.           INY
  438.           BRA :1
  439.  
  440. * ----------------------------------------------- *
  441.  
  442. * Restore the registers by pulling from the stack,
  443. * reset 1-second interrupt (bit 6 - SCANINT), and
  444. * return from interrupt (RTI) to BASIC.
  445.  
  446. NOMATCH   PLY
  447.           PLX
  448.           PLA
  449.           PLB
  450.           PLP
  451.  
  452.           LDA SCANINT
  453.           AND #%10111111
  454.           STA SCANINT
  455.  
  456.           RTI
  457.  
  458. * ----------------------------------------------- *
  459.  
  460. RINGBELL  LDA #"N"       ;first, remove the 'S'
  461.           STA TEFLAG     ;from the flag location
  462.                          ;so APPEAR knows the alarm
  463.                          ;has been activated
  464.           JSR BELL
  465.           LDA KEYBOARD   ;read keyboard
  466.           CMP #$80       ;was a key pressed?
  467.           BCC RINGBELL   ;no - ring again
  468.           STA STROBE     ;clear character from kybd
  469.  
  470.           PLY            ;restore registers
  471.           PLX
  472.           PLA
  473.           PLB
  474.           PLP
  475.  
  476. DONE7     RTI            ;Event displayed. Back to
  477.                          ;BASIC
  478.  
  479. *============= messages and data storage ==========*
  480.  
  481. RMSSG     ASC "YOU'VE SET AN ALARM FOR - ",8D,8D,00
  482.  
  483. RMSSG2    HEX 8D,8D
  484.           ASC "DO YOU WISH TO REMOVE THIS ALARM "
  485.           ASC "AND SET A NEW ONE? (Y or N) ",00
  486.  
  487. TMSSG     ASC "ENSURE THAT IIGS CLOCK",8D
  488.           ASC "IS IN AM - PM FORMAT",8D,8D
  489.  
  490.           ASC "Set Time (example - 8:30_PM",8D
  491.           ASC "CONTROL-Q and RETURN to Quit):",8D,8D
  492.           HEX 00
  493.  
  494. ERROR     ASC "INVALID TIME ENTRY - REENTER:",8D
  495.           ASC "(example - 8:30_PM)",8D,00
  496.  
  497. EMSSG     HEX 8D
  498.           ASC "Event or Appointment",8D
  499.           ASC "(Message limited to 160 characters"
  500.           ASC " -",8D
  501.           ASC "4 full screen lines in 40-column"
  502.           ASC " mode"8D
  503.           ASC "CONTROL-Q and RETURN to Quit):",8D,8D
  504.           HEX 00
  505.  
  506. EMSSG2    HEX 8D
  507.           ASC "Is Message OK? (Y or N) ",00
  508.  
  509. CMSSG     ASC "Is time OK? (Y or N) ",00
  510.  
  511. CMSSG2    ASC "Type 'Y' or 'N' only ",00
  512.  
  513. CRS       HEX 8D,8D,8D,8D,8D,8D,8D,00
  514.  
  515. DTBUFF    DS 20          ;date and time buffer for
  516.                          ;ReadTimeASCII
  517.  
  518. TEBUFF                   ;time and event buffer
  519.